package com.jbp.job;

import com.jbp.redis.RedisConfigService;
import com.jbp.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 用户任务
 * */
//@Component
//@Configuration
public class UserJob {
    @Autowired
    private LuckyUtil luckyUtil;
    @Autowired
    private UserNobilityService userNobilityService;
    /**
     * 计算房间基础爆率
     * */
    @Autowired
    private RedisConfigService redisConfigService;

    @Scheduled(fixedDelay = 1000*10)
    public void setData(){
        if (redisConfigService.setLock("user_set_luck_rate", 60*30)) {
            System.out.println("计算房间爆率");
            luckyUtil.setRoomRate();
            System.out.println("计算设备爆率");
            luckyUtil.setDeviceRate();
            System.out.println("计算ip爆率");
            luckyUtil.setIpRate();
        }
    }

    /**
     * 刷新爵位
     * */
    @Scheduled(fixedDelay = 1000*10)
    public void keepNobility(){
        if (redisConfigService.setLock("user_keep_nobility", 60)) {
            userNobilityService.updateLevel();
        }
    }
}

